package com.dailyblue.javaee.controller;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/axios_get")
public class AxiosGetController  extends HttpServlet {
//处理get
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        System.out.println("name:" + name);
        System.out.println("gender:" + gender);
        PrintWriter out = response.getWriter();
        out.println("get:name:" + name + ",gender:" + gender);
    }
    // post
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        System.out.println("name:" + name);
        System.out.println("gender:" + gender);
        PrintWriter out = response.getWriter();
        out.println("post:name:" + name + ",gender:" + gender);
    }
    // put
    protected void doPut(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        System.out.println("name:" + name);
        System.out.println("gender:" + gender);
        PrintWriter out = response.getWriter();
        out.println("put:name:" + name + ",gender:" + gender);
    }
    // delete
    protected void doDelete(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        System.out.println("name:" + name);
        System.out.println("gender:" + gender);
        PrintWriter out = response.getWriter();
        out.println("delete:name:" + name + ",gender:" + gender);
    }
}